package com.ruoyi.yljf.controller.AppController;

import cn.hutool.core.bean.BeanUtil;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.security.annotation.Anonymous;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.yljf.domain.Blessing;
import com.ruoyi.yljf.domain.Drug;
import com.ruoyi.yljf.domain.GoodsOrder;
import com.ruoyi.yljf.domain.Order;
import com.ruoyi.yljf.domain.dto.BlessingDTO;
import com.ruoyi.yljf.domain.dto.CommonTypeDTO;
import com.ruoyi.yljf.domain.dto.CreateDTO.CerateOrderDTO;
import com.ruoyi.yljf.domain.dto.OrderDTO;
import com.ruoyi.yljf.domain.vo.*;
import com.ruoyi.yljf.service.*;
import com.sun.org.apache.bcel.internal.generic.RETURN;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 订单
 */
@RestController
@RequestMapping("/api/order")
public class ApiOrderController extends BaseController {

    @Resource
    private IOrderService orderService;
    @Resource
    private IGoodsOrderService goodsOrderService;
    @Resource
    private IBlessingService blessingService;

//    /**
//     * 查询全部订单列表
//     */
//    @GetMapping("/list")
//    public TableDataInfo getOrderList(OrderDTO orderDTO) {
//        if (orderDTO.getOrderType()==5) {	//实物商品表
//            GoodsOrder goodsOrder = new GoodsOrder();
//            goodsOrder.setUserId(getUserId());
//            goodsOrder.setStatu(orderDTO.getStatus());
//            List<GoodsOrder> goodsOrders = goodsOrderService.selectGoodsOrderList(goodsOrder);
//            List<GoodsOrderVO> goodsOrderVOS = goodsOrderService.selectGoodsOrders(goodsOrders);
//            return getDataTableInfo(goodsOrderVOS,goodsOrders);
//        }else{		//查询订单表
//            Order order = new Order();
//            order.setOrderType(orderDTO.getOrderType());
//            order.setStatus(orderDTO.getStatus());
//            order.setUserId(getUserId());
//            List<Order> orders = orderService.selectOrderList(order);
//            List<OrderVO> orderVOS = orderService.selectOrders(orders);
//            return getDataTableInfo(orderVOS,orders);
//
//        }
//    }

    /**
     * 订单列表--课程列表接口
     */
    @Anonymous
    @GetMapping("/courseOrderList")
    public TableDataInfo courseOrderList(OrderDTO orderDTO) {
		//查询订单表
        List<Order> orders = orderService.selectAllOrder(orderDTO);
        List<OrderVO> orderVOS = orderService.selectOrders(orders);
        return getDataTableInfo(orderVOS,orders);
    }

    /**
     * 订单列表--祈福列表接口
     */
    @Anonymous
    @GetMapping("/blessingOrderList")
    public TableDataInfo blessingOrderList(BlessingDTO blessingDTO) {
        startPage();
        List<Blessing> orders = blessingService.selectAllOrder(blessingDTO);
        List<BlessingVO> blessingVOS = BeanUtil.copyToList(orders, BlessingVO.class);
        return getDataTableInfo(blessingVOS,orders);
    }

    /**
     * 订单列表--活动列表接口
     */
    @Anonymous
    @GetMapping("/activeOrderList")
    public TableDataInfo activeOrderList(OrderDTO orderDTO) {
        //查询订单表
        List<Order> orders = orderService.selectActiveOrder(orderDTO);
        List<OrderVO> orderVOS = orderService.selectOrders(orders);
        return getDataTableInfo(orderVOS,orders);
    }

    /**
     * 订单列表--书籍列表接口
     */
    @Anonymous
    @GetMapping("/bookOrderList")
    public TableDataInfo bookOrderList(OrderDTO orderDTO) {
        //查询订单表
        List<Order> orders = orderService.selectBookOrder(orderDTO);
        List<OrderVO> orderVOS = orderService.selectOrders(orders);
        return getDataTableInfo(orderVOS,orders);
    }

    /**
     * 订单列表--积分购买商品列表接口
     */
    @Anonymous
    @GetMapping("/pointsOrderList")
    public TableDataInfo pointsOrderList(OrderDTO orderDTO) {
        //查询订单表
        List<GoodsOrder> goodsOrders = orderService.selectPointsOrder(orderDTO);
        List<GoodsOrderVO> goodsOrderVOS = goodsOrderService.selectGoodsOrders(goodsOrders);
        return getDataTableInfo(goodsOrderVOS,goodsOrders);
    }


    /**
     * 根据id查询订单详情
     */
    @Anonymous
    @GetMapping("/getOrderById")
    public AjaxResult getDrugById(@RequestParam Long id) {
        Order byId = orderService.getById(id);
        return success(BeanUtil.copyProperties(byId, OrderDetailVO.class));
    }

    /**
     * 创建订单--课程-活动-文章购买
     */
    @GetMapping("/createOrder")
    public AjaxResult createOrder(CerateOrderDTO dto) {
        return orderService.createOrder(dto);
    }

    /**
     * 去付款
     */
    @GetMapping("/toPay/{number}")
    public AjaxResult toPay(@PathVariable("number") String number) {
        return orderService.toPay(number);
    }

}
